﻿using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;

namespace StockLib.Data
{
    public class NewsDataFile
    {
        #region 文件目录定义
        private const string DIR_NEWS = @"news\";
        #endregion

        /// <summary>
        /// 文件存储的根路径
        /// </summary>
        public string RootPath { get; set; }

        /// <summary>
        /// 单例实例
        /// </summary>
        private static NewsDataFile _instance = new NewsDataFile();

        /// <summary>
        /// 构造函数
        /// </summary>
        private NewsDataFile()
        {
            RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
        }

        /// <summary>
        /// 访问单例
        /// </summary>
        /// <returns></returns>
        public static NewsDataFile Instance
        {
            get
            {
                return _instance;
            }
        }

        /// <summary>
        /// 初始化数据库
        /// </summary>
        public virtual void Init()
        {
            if (string.IsNullOrEmpty(RootPath))
                return;

            if (!Directory.Exists(RootPath))
                return;
        }

        /// <summary>
        /// 释放数据库
        /// </summary>
        public virtual void Release()
        {
        }

        /// <summary>
        /// 根据市场类型和数据类型，确定文件名称
        /// </summary>
        /// <param name="market">市场类型</param>
        /// <param name="dataType">数据类型</param>
        /// <returns></returns>
        public string GetFileName(string fileName)
        {
            return RootPath + DIR_NEWS + fileName;
        }
    }
}
